<?php

class coreRouter
{
    protected  $params = array();
    private $class = null;
    protected $router = null;

    //protected $directory = 'main';
    protected $directory = 'cont';
    private $defClassString = 'index';
    //private $controllerString = 'Ct';
    private $controllerString = '';
    private $divisionString = '_';


    function __construct()
    {
        $this->_routing();
    }

    public function _routing()
    {
        $c = $this->params[SC_VARIABLE_CONTOLLER];

        // controller 값이 없을경우 default 를 지정
        if (empty($c) === true) {
            $this->class = $this->router.ucfirst($this->directory).ucfirst($this->defClassString);

        } else {
            // '_' 구분자가 있을 경우 해당 구분자로 class 를 조합한다.
            if (strpos($c, $this->divisionString) !== false) {
                $aCtrl = explode($this->divisionString, $c);
                $_aClass = array();
                for ($i=0; $i<count($aCtrl); $i++) {
                    $_aClass[] = ucfirst($aCtrl[$i]);
                }
                $this->class = $this->router.implode($_aClass).$this->controllerString;

            // 구부자 없이 단일구조일 때
            } else {
                $this->class = $this->router.ucfirst($c).$this->controllerString;
            }
        }

        $sClssName = $this->class;
        
        // class exists check
        //if (!class_exists($sClssName)) {
            //echo '404 Not Found';
            //exit;
        //}

        // class 호출
        $oClass = new ${sClssName}($this->params);
    }
}